﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace UserInterface.HelperForms
{
    public partial class EditBrand : Form
    {
        public int BrandID        { get; set; }
        public string LogoExtension { get; set; }
        public EditBrand()
        {
            InitializeComponent();
        }

        private void SelectLogoButton_Click(object sender, EventArgs e)
        {
            OpenFile.ShowDialog(this);
            LogoImage.Image = System.Drawing.Image.FromFile(OpenFile.FileName);
            LogoExtension = OpenFile.FileName.Substring(OpenFile.FileName.LastIndexOf("."), OpenFile.FileName.Length - OpenFile.FileName.LastIndexOf("."));


        }

        private void CancelButton_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void SaveButton_Click(object sender, EventArgs e)
        {
            OneSystems.Data.Entities.Category category = (OneSystems.Data.Entities.Category)Categories.SelectedItem;
            OneSystems.BusinessLogic.DebtLogic.SaveBrand(BrandID, category.CategoryID, BrandNameTextbox.Text, DescriptionTextBox.Text, (Image)LogoImage.Image, LogoExtension);
            this.Close();
        }

        private void EditBrand_Load(object sender, EventArgs e)
        {

            foreach (OneSystems.Data.Entities.Category category in OneSystems.BusinessLogic.DebtLogic.Categories)
            {
                Categories.Items.Add(category);
            }
            Categories.SelectedIndex = 0;
        }
    }
}
